package com.example.myspringframework.beans.factory.config;

import com.example.myspringframework.beans.BeansException;
import com.example.myspringframework.beans.PropertyValues;

/**
 * 扩展BeanPostProcessor，对实例化执行前后进行扩展
 */
public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
    /**
     * bean的实例化之前执行
     */
    default Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        return null;
    }

    /**
     * bean的实例化之后执行
     */
    default boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        return true;
    }

    /**
     * bean实例化之后，设置属性之前执行
     */
    default PropertyValues postProcessPropertyValues(PropertyValues pvs, Object bean, String beanName) throws BeansException {
        return pvs;
    }

    /**
     * 提前暴露bean的引用，用于解决包含动态代理的循环依赖问题
     */
    default Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
